#ifndef _CAIPU_
#define _CAIPU_

#include "stdio.h"

//#define _dianfanguo_

#define CMD_SINGLE 

#define _CAIPU_STD_
#define _dianfanbao_

#define CAIPU_VERSION (0x01)


#define TARGET_U 0x00
#define TARGET_C 0x01

#define K_DIANCILU (0X80)
#define K_GUO (0X02)

#define F_AND 0XC9//201
#define F_OR 0XCa//202
#define F_EQUAL 0XCb//203
#define F_NOT 0XCc//204
#define F_SMALLER 0XCd//205
#define F_BIGGER 0Xce//206
#define F_SMALLER_EQUAL 0XCf//207
#define F_BIGGER_EQUAL 0Xd0//208
#define F_LEFT 0Xd1//209
#define F_RIGHT 0Xd2//210

typedef enum
{
	CMD_RUN  = 0x01,
	CMD_JUMP =0X02,
	CMD_SLEEP=0X03,
}CAIPU_RUN_CMD;


typedef enum
{
	C_LJ_DP_BYTE  = 0x00,
	C_LJ_DP_INT16 = 0x10,
	C_LJ_DP_UINT16 = 0x20,
	C_LJ_DP_INT32 = 0x30,
	C_LJ_DP_UINT32 = 0x40,
	C_LJ_DP_INT64 = 0x50,
	C_LJ_DP_UINT64 = 0x60,
	C_LJ_DP_FLOAT = 0x70,
	C_LJ_DP_DOUBLE = 0x80,
	C_LJ_DP_STRING = 0x90,
	C_LJ_DP_BINARY = 0XA0,
	C_LJ_DP_INT8=0XC0,
}LJ_DATAPOINTTYPE_CAIPU;


typedef enum
{
	LJ_PUSH_MODE_ALL_CAN  = 0x00,
	LJ_PUSH_MODE_CHANGE_CAN_WICH_BACKLIST  = 0x01,
}LJ_PUSH_MODE_KIND;

#define LJ_PUSH_MODE_ORI (LJ_PUSH_MODE_CHANGE_CAN_WICH_BACKLIST)


#define F_END 0X61
#define P_TIMER 0x62
#define P_STEP 0x63
#define F_KIND 0X0F
#define F_QUERY 0x0e

#define F_CAIPU_INDEX 100

#define F_CAIPU_FIRST 101
#define F_CAIPU_MAX 199


#define F_TRUE 0xe1//210
#define F_FALSE 0xe2//211

#define F_WRONG 0xff
#define F_EMPTY 0xfe

#define CAIPU_WIFI_PIP (0xf0)
#define CAIPU_WIFI_SET_UPDATE (0XFC)
#define CAIPU_WIFI_END (0xfb)
#define CAIPU_WIFI_STEP (0XFA)
#define CAIPU_WIFI_MENU_ID (0x04)//(0XF9)

#define U_HEAD 0x64
#define U_STEP 0xFA
#define U_BEGIN 0X63
#define U_HEARTBEAT 0XF2

#define stack_MAX 10



#define POINT_INT_NUM_MAX (20)
#define POINT_CHAR_NUM_MAX (3)
#define POINT_CHAR_LEN_MAX (256)

#define POINT_ALL_NUM_MAX (POINT_INT_NUM_MAX+POINT_CHAR_NUM_MAX)

#define CMD_LEN_MAX (POINT_CHAR_LEN_MAX+2)
#define CMD_BUF_MAX (POINT_CHAR_LEN_MAX+3)
#define JUDGE_BUF_MAX 64

#define CAIPU_BUZHOU_COUNT_MAX 64//32//32
#define CAIPU_BUF_MAX (128)//(JUDGE_BUF_MAX+CMD_LEN_MAX+1)//64

#define JUDGE_DELAY_TIME 2 //s
#define JUDGE_DELAY_TIME_1 2 //s

#define TONGBU_DATA_BUF_LEN (64)
#define LIANDONG_INDEX 0x21

typedef struct {
	unsigned char full;
    unsigned char index;
    unsigned char kind;
    unsigned char len;
    unsigned int value;
	unsigned char change;
}point_int_st;


typedef struct {
	unsigned char full;
    unsigned char index;
    unsigned char kind;
    unsigned short len;
    unsigned char value[POINT_CHAR_LEN_MAX];
	unsigned char change;
}point_char_st;



// #define log_zzc(format,...) printf(format ,##__VA_ARGS__)
// #define log_zzc_error(format,...) printf("error:"format ,##__VA_ARGS__)
// #define log_zzc(...) 

typedef void (*caipu_send_buf_fun_t)(unsigned char *buf, unsigned short len);
//typedef void (*caipu_air_send_fun)(unsigned char *buf, unsigned short len);


//extern void caipu_u_deal_64(unsigned char *buf,unsigned char len);
//extern void caipu_u_deal_65(unsigned char index,unsigned char *buf,unsigned short len);
//extern void caipu_end(void);
// extern void caipu_loop(void);
//extern unsigned char  caipu_guo_refresh_value_86(unsigned char *buf,unsigned short len);
//extern unsigned char  caipu_dian_refresh_value_86(unsigned char *buf,unsigned short len);
//extern unsigned char  caipu_guo_refresh_value_85(unsigned char *buf,unsigned short len);
// extern void judge_time_loop(void);//s
extern void caipu_loop_fun(void);//50ms

extern void caipu_init(caipu_send_buf_fun_t u_send_buf_fun);
//extern void get_guo_tongbu_data(unsigned char *buf_out,unsigned short *len_out);
//extern void get_guo_status_data(unsigned char *buf_out,unsigned short *len_out);
//extern void get_guo_dian_status_data(unsigned char *buf_out,unsigned short *len_out);
//extern void get_dian_status_data(unsigned char *buf_out,unsigned short *len_out);
//extern void get_dian_tongbu_data(unsigned char *buf_out,unsigned short *len_out);

extern void set_point_int_value(unsigned char index,unsigned char kind,unsigned char len,unsigned char *buf);
extern void set_point_char_value(unsigned char index,unsigned char kind,unsigned short len,unsigned char *buf);
extern void reset_change(void);

extern unsigned char caipu_deal_85(unsigned char *buf,unsigned short len);
extern void caipu_deal_86(unsigned char *buf,unsigned short len);
extern unsigned char caipu_point_deal(unsigned char *buf,unsigned short len);

/*
@param unchack need to be raw lentgh of POINT_ALL_NUM_MAX
@return  1=change 0=unchange
*/
extern unsigned char check_change(unsigned char *unchack,unsigned char len);//unchack= lj_setting[POINT_ALL_NUM_MAX+1]={0}; len=lj_setting_len

// extern unsigned char dev_kind;
// extern unsigned char get_ack;

// extern unsigned char liandong_gonglv;
extern unsigned char caipu_change;

// extern unsigned char lj_push_mode;
// extern unsigned char lj_setting[POINT_ALL_NUM_MAX+1];
// extern int lj_setting_len;
// extern unsigned int lj_time_can_push;

/*
 *
 * @param  len is needed bigger than 10
 */
extern void caipu_change_buf_fill(unsigned char *buf,unsigned char *len);

extern unsigned char  get_caipu_change(void);
extern void reset_caipu_change(void);
extern void set_caipu_change(void);
extern void need_end_caipu_fun(void);
extern unsigned char caipu_is_running(void);

extern unsigned char get_point_int(unsigned char index,unsigned int *out);

extern unsigned char  point_find_int_num(unsigned char index);


#endif
